package com.rock.code.report.inspect.service.impl;

import com.rock.code.base.service.impl.BaseServiceImpl;
import com.rock.code.common.handover.DataSource;
import com.rock.code.report.inspect.dao.JbInspectViewDao;
import com.rock.code.report.inspect.service.JbInspectViewService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 监控 Service 实现
 *
 * @author xubh
 * @date 2018/01/21
 */
@Service
public class JbInspectViewServiceImpl extends BaseServiceImpl<JbInspectViewDao> implements JbInspectViewService {

    @Resource
    private JbInspectViewDao jbInspectViewDao;

    @Override
    @DataSource("inspect")
    public List queryInspectAllTask() {
        return jbInspectViewDao.queryInspectAllTask();
    }

    @Override
    @DataSource("inspect")
    public List queryAutoManualInspectTask() {
        return jbInspectViewDao.queryAutoManualInspectTask();
    }

    @Override
    @DataSource("inspect")
    public List queryTaskExecuteStatus() {
        return jbInspectViewDao.queryTaskExecuteStatus();
    }

    @Override
    @DataSource("inspect")
    public List queryPlanExecuteCount() {
        return jbInspectViewDao.queryPlanExecuteCount();
    }

    @Override
    @DataSource("inspect")
    public List queryManualExecuteTask() {
        return jbInspectViewDao.queryManualExecuteTask();
    }

    @Override
    @DataSource("inspect")
    public List querySystemHealthCount() {
        return jbInspectViewDao.querySystemHealthCount();
    }

    @Override
    @DataSource("inspect")
    public List queryInspectCoverRate() {
        return jbInspectViewDao.queryInspectCoverRate();
    }

    @Override
    @DataSource("inspect")
    public List queryInspectTaskTimeDis() {
        return jbInspectViewDao.queryInspectTaskTimeDis();
    }

    @Override
    @DataSource("inspect")
    public List querySystemThirtyDayHealth() {
        return jbInspectViewDao.querySystemThirtyDayHealth();
    }

    @Override
    @DataSource("inspect")
    public List queryThirtyDayCoverTrend() {
        return jbInspectViewDao.queryThirtyDayCoverTrend();
    }

    @Override
    @DataSource("inspect")
    public List queryTaskGroup() {
        return jbInspectViewDao.queryTaskGroup();
    }

    @Override
    @DataSource("inspect")
    public List queryTaskGroupHealth(HashMap map) {
        return jbInspectViewDao.queryTaskGroupHealth(map);
    }

    @Override
    @DataSource("inspect")
    public List queryTaskGroupThirtyDayHealth(HashMap map) {
        return jbInspectViewDao.queryTaskGroupThirtyDayHealth(map);
    }
    @Override
    @DataSource("inspect")
    public HashMap taskGroupPollingOverviewService() {
        HashMap hashMap=new HashMap();
        List list1=jbInspectViewDao.taskGroupSumOverview();
        hashMap.put("allNum",list1);
        List listGroupTwo=new ArrayList();
        List listGroupTaskId=new ArrayList();
        List listNum=new ArrayList();
        List list2 =new ArrayList();
        try{
            listGroupTwo = jbInspectViewDao.queryGroupTwo();
             for(int i = 0;i<listGroupTwo.size();i++){
                 Map mapGroupTwo = (Map) listGroupTwo.get(i);
//                 long e=System.currentTimeMillis();
                 listGroupTaskId=jbInspectViewDao.allHaveTaskGroup(mapGroupTwo);
                 HashMap map1=new HashMap();
                 map1.put("list",listGroupTaskId);
                 listNum=jbInspectViewDao.queryGroupTaskNum(map1);
//                 long f=System.currentTimeMillis();
//                 System.out.println("========"+(f-e)/1000+"秒");
                 for(int j=0;j<listNum.size();j++){
                     Map map2=(Map) listNum.get(j);
//                     mapGroupTwo.put("ALL_COUNT",map2.get("ALL_COUNT"));
//                     mapGroupTwo.put("SUCCESS_COUNT",map2.get("SUCCESS_COUNT"));
//                     mapGroupTwo.put("FAIL_COUNT",map2.get("FAIL_COUNT"));
//                     mapGroupTwo.put("P",map2.get("P"));
//
                     mapGroupTwo.putAll(map2);
                 }
                 list2.add(mapGroupTwo);
                 hashMap.put("tableData",list2);
             }
        }catch ( Exception e){
            e.printStackTrace();
        }
//        System.out.println(list);
        return hashMap;
    }
}